package de.stefanocke.roo.wicket.base;

import org.springframework.roo.model.JavaSymbolName;
import org.springframework.roo.model.JavaType;

import de.stefanocke.roo.xtend.Parameter;

public enum StandardParam {
	ID("id", new JavaType("java.lang.String")), 
	MODEL("model", new JavaType("org.apache.wicket.model.Model")),
	MARKUPPROVIDER("markupProvider", new JavaType("org.apache.wicket.markup.html.WebMarkupContainer")),
	INLIST("inList", JavaType.BOOLEAN_PRIMITIVE);
	
	private JavaType type;
	private String name;

	private StandardParam(String name, JavaType type){
		this.name=name;
		this.type=type;
	}
		
	public JavaType getType() {
		return type;
	}
	
	@Override
	public String toString() {
		return name;
	}
	
	public static StandardParam toStandardParam(JavaSymbolName name){
		try{
			return valueOf(name.getSymbolName().toUpperCase());
		} catch (Exception e) {
			return null;
		}
		
	}
	
	public static StandardParam toStandardParam(Parameter param ){
		try{
			return valueOf(param.getName().getSymbolName().toUpperCase());
		} catch (Exception e) {
			//TODO: Do type matching if name does not work.
			return null;
		}
		
	}
	
	public Parameter toParam(){
		return Parameter.param(type, name);		
	}
}
